1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
use std::rc::Rc;
use crate::co;
use crate::decl::*;
use crate::gui::{*, privs::*};
use crate::msg::*;
use crate::prelude::*;
/// Exposes window
/// [messages](https://learn.microsoft.com/en-us/windows/win32/winmsg/about-messages-and-message-queues).
///
/// You cannot directly instantiate this object, it is created internally by the
/// window.
pub struct WindowEvents(WindowEventsPriv);
impl WindowEvents {
#[must_use]
pub(in crate::gui) const fn new(is_dialog: bool) -> Self {
Self(WindowEventsPriv::new(is_dialog))
}
pub(in crate::gui) fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub(in crate::gui) fn clear_events(&self) {
self.0.clear_events()
}
/// Searches for the last added user function for the given message, and
/// runs if it exists, returning the result.
pub(in crate::gui) fn process_last_message(&self,
hwnd: &HWND,
wm_any: WndMsg,
) -> AnyResult<WmRet>
{
self.0.process_last_message(hwnd, wm_any)
}
/// Event to any [window message](crate::co::WM).
///
/// Instead of using this event, you should always prefer the specific
/// events, which will give you the correct message parameters. This generic
/// method should be used only when you have a custom, non-standard window
/// message – which should be pretty rare.
///
/// # Examples
///
/// Handling a custom, user-defined message:
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, co, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// let CUSTOM_MSG = unsafe { co::WM::from_raw(0x1234) };
///
/// wnd.on().wm(
/// CUSTOM_MSG,
/// move |p: msg::WndMsg| -> w::AnyResult<gui::WmRet> {
/// println!("Msg ID: {}", p.msg_id);
/// Ok(gui::WmRet::HandledOk)
/// },
/// );
/// ```
pub fn wm<F>(&self, ident: co::WM, func: F)
where F: Fn(WndMsg) -> AnyResult<WmRet> + 'static,
{
self.0.wm(ident, move |_, p| func(p));
}
/// [`WM_COMMAND`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-command)
/// message, for specific code and control ID.
///
/// A command notification must be narrowed by the
/// [command code](crate::co::CMD) and the control ID, so the closure will
/// be fired for that specific control at that specific event.
///
/// Instead of using this event, you should always prefer the specific
/// command notifications, which will give you the correct message
/// parameters. This generic method should be used only when you have a
/// custom, non-standard window notification.
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, co, gui};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// const CTRL_ID: u16 = 1010;
///
/// wnd.on().wm_command(
/// CTRL_ID,
/// co::BN::CLICKED,
/// move || -> w::AnyResult<gui::WmRet> {
/// println!("Button clicked!");
/// Ok(gui::WmRet::HandledOk)
/// },
/// );
/// ```
pub fn wm_command<F>(&self,
ctrl_id: impl Into<u16>,
code: impl Into<co::CMD>,
func: F,
)
where F: Fn() -> AnyResult<WmRet> + 'static,
{
self.0.wm_command(ctrl_id, code, func);
}
/// [`WM_NOTIFY`](crate::msg::wm::Notify) message, for specific ID and
/// notification code.
///
/// Instead of using this event, you should always prefer the specific
/// notifications, which will give you the correct notification struct. This
/// generic method should be used only when you have a custom, non-standard
/// window notification.
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, co, gui};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// const CTRL_ID: u16 = 1010;
///
/// wnd.on().wm_notify(
/// CTRL_ID,
/// co::NM::DBLCLK,
/// move |_| -> w::AnyResult<gui::WmRet> {
/// println!("Button clicked!");
/// Ok(gui::WmRet::HandledOk)
/// },
/// );
/// ```
pub fn wm_notify<F>(&self,
id_from: impl Into<u16>,
code: impl Into<co::NM>,
func: F,
)
where F: Fn(wm::Notify) -> AnyResult<WmRet> + 'static,
{
self.0.wm_notify(id_from, code, func);
}
/// [`WM_TIMER`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-timer)
/// message, narrowed to a specific timer ID.
pub fn wm_timer<F>(&self, timer_id: usize, func: F)
where F: Fn() -> AnyResult<()> + 'static,
{
self.0.wm_timer(timer_id, func);
}
/// [`WM_COMMAND`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-command)
/// message, handling both `CMD::Accelerator` and `CMD::Menu`, for a
/// specific command ID.
///
/// Ideal to be used with menu commands whose IDs are shared with
/// accelerators, like menu items.
pub fn wm_command_accel_menu<F>(&self, ctrl_id: impl Into<u16> + Copy, func: F)
where F: Fn() -> AnyResult<()> + 'static,
{
let shared_func = Rc::new(func);
self.wm_command(ctrl_id, co::CMD::Menu, {
let shared_func = shared_func.clone();
move || {
shared_func()?;
Ok(WmRet::HandledOk)
}
});
self.wm_command(ctrl_id, co::CMD::Accelerator, {
let shared_func = shared_func.clone();
move || {
shared_func()?;
Ok(WmRet::HandledOk)
}
});
}
pub_fn_wm_withparm_noret! { wm_activate, co::WM::ACTIVATE, wm::Activate;
/// [`WM_ACTIVATE`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-activate)
/// message.
}
pub_fn_wm_withparm_noret! { wm_activate_app, co::WM::ACTIVATEAPP, wm::ActivateApp;
/// [`WM_ACTIVATEAPP`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-activateapp)
/// message.
}
/// [`WM_APPCOMMAND`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-appcommand)
/// message.
pub fn wm_app_command<F>(&self, func: F)
where F: Fn(wm::AppCommand) -> AnyResult<()> + 'static,
{
self.wm(co::WM::APPCOMMAND, move |p| {
func(wm::AppCommand::from_generic_wm(p))?;
Ok(WmRet::HandledWithRet(1)) // TRUE
});
}
pub_fn_wm_noparm_noret! { wm_cancel_mode, co::WM::CANCELMODE;
/// [`WM_CANCELMODE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-cancelmode)
/// message.
}
pub_fn_wm_withparm_noret! { wm_capture_changed, co::WM::CAPTURECHANGED, wm::CaptureChanged;
/// [`WM_CAPTURECHANGED`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-capturechanged)
/// message.
}
pub_fn_wm_withparm_noret! { wm_char, co::WM::CHAR, wm::Char;
/// [`WM_CHAR`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-char)
/// message.
}
pub_fn_wm_noparm_noret! { wm_child_activate, co::WM::CHILDACTIVATE;
/// [`WM_CHILDACTIVATE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-childactivate)
/// message.
}
pub_fn_wm_noparm_noret! { wm_close, co::WM::CLOSE;
/// [`WM_CLOSE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-close)
/// message.
///
/// # Default handling
///
/// If you handle this event, you'll overwrite the default handling in:
///
/// * dialog [`WindowMain`](crate::gui::WindowMain) – calls [`DestroyWindow`](crate::prelude::user_Hwnd::DestroyWindow);
/// * dialog [`WindowModal`](crate::gui::WindowModal) – calls [`EndDialog`](crate::prelude::user_Hwnd::EndDialog);
/// * non-dialog [`WindowModal`](crate::gui::WindowModal) – re-enables parent and calls [`DestroyWindow`](crate::prelude::user_Hwnd::DestroyWindow).
}
pub_fn_wm_noparm_noret! { wm_context_menu, co::WM::CONTEXTMENU;
/// [`WM_CONTEXTMENU`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-contextmenu)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_btn, co::WM::CTLCOLORBTN, wm::CtlColorBtn;
/// [`WM_CTLCOLORBTN`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorbtn)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_dlg, co::WM::CTLCOLORDLG, wm::CtlColorDlg;
/// [`WM_CTLCOLORDLG`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-ctlcolordlg)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_edit, co::WM::CTLCOLOREDIT, wm::CtlColorEdit;
/// [`WM_CTLCOLOREDIT`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcoloredit)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_list_box, co::WM::CTLCOLORLISTBOX, wm::CtlColorListBox;
/// [`WM_CTLCOLORLISTBOX`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorlistbox)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_scroll_bar, co::WM::CTLCOLORSCROLLBAR, wm::CtlColorScrollBar;
/// [`WM_CTLCOLORSCROLLBAR`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorscrollbar)
/// message.
}
pub_fn_wm_ctlcolor! { wm_ctl_color_static, co::WM::CTLCOLORSTATIC, wm::CtlColorStatic;
/// [`WM_CTLCOLORSTATIC`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorstatic)
/// message.
}
/// [`WM_CREATE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-create)
/// message, sent only to non-dialog windows. Dialog windows receive
/// [`WM_INITDIALOG`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-initdialog)
/// instead.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_create(
/// move |p: msg::wm::Create| -> w::AnyResult<i32> {
/// println!("Client area: {}x{}",
/// p.createstruct.cx,
/// p.createstruct.cy,
/// );
/// Ok(0)
/// },
/// );
/// ```
pub fn wm_create<F>(&self, func: F)
where F: Fn(wm::Create) -> AnyResult<i32> + 'static,
{
self.wm(co::WM::CREATE, move |p| {
let ret_val = func(wm::Create::from_generic_wm(p))? as isize;
Ok(WmRet::HandledWithRet(ret_val))
});
}
pub_fn_wm_withparm_noret! { wm_dead_char, co::WM::DEADCHAR, wm::DeadChar;
/// [`WM_DEADCHAR`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-deadchar)
/// message.
}
pub_fn_wm_withparm_boolret! { wm_delete_item, co::WM::DELETEITEM, wm::DeleteItem;
/// [`WM_DELETEITEM`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-deleteitem)
/// message.
}
pub_fn_wm_noparm_noret! { wm_destroy, co::WM::DESTROY;
/// [`WM_DESTROY`](crate::msg::wm::Destroy) message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_destroy(
/// move || -> w::AnyResult<()> {
/// println!("Window is gone, goodbye!");
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_device_change, co::WM::DEVICECHANGE, wm::DeviceChange;
/// [`WM_DEVICECHANGE`](https://learn.microsoft.com/en-us/windows/win32/devio/wm-devicechange)
/// message.
}
pub_fn_wm_withparm_noret! { wm_display_change, co::WM::DISPLAYCHANGE, wm::DisplayChange;
/// [`WM_DISPLAYCHANGE`](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-displaychange)
/// message.
}
pub_fn_wm_withparm_noret! { wm_drop_files, co::WM::DROPFILES, wm::DropFiles;
/// [`WM_DROPFILES`](https://learn.microsoft.com/en-us/windows/win32/shell/wm-dropfiles)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_drop_files(
/// move |mut p: msg::wm::DropFiles| -> w::AnyResult<()> {
/// for dropped_file in p.hdrop.DragQueryFile()? {
/// let dropped_file = dropped_file?;
/// println!("Dropped: {}", dropped_file);
/// }
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_enable, co::WM::ENABLE, wm::Enable;
/// [`WM_ENABLE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-enable)
/// message.
}
pub_fn_wm_withparm_noret! { wm_end_session, co::WM::ENDSESSION, wm::EndSession;
/// [`WM_ENDSESSION`](https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-endsession)
/// message.
}
pub_fn_wm_withparm_noret! { wm_enter_idle, co::WM::ENTERIDLE, wm::EnterIdle;
/// [`WM_ENTERIDLE`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-enteridle)
/// message.
}
pub_fn_wm_withparm_noret! { wm_enter_menu_loop, co::WM::ENTERMENULOOP, wm::EnterMenuLoop;
/// [`WM_ENTERMENULOOP`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-entermenuloop)
/// message.
}
pub_fn_wm_noparm_noret! { wm_enter_size_move, co::WM::ENTERSIZEMOVE;
/// [`WM_ENTERSIZEMOVE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-entersizemove)
/// message.
}
/// [`WM_ERASEBKGND`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-erasebkgnd)
/// message.
pub fn wm_erase_bkgnd<F>(&self, func: F)
where F: Fn(wm::EraseBkgnd) -> AnyResult<i32> + 'static,
{
self.wm(co::WM::ERASEBKGND, move |p| {
let ret_val = func(wm::EraseBkgnd::from_generic_wm(p))? as isize;
Ok(WmRet::HandledWithRet(ret_val))
});
}
pub_fn_wm_withparm_noret! { wm_exit_menu_loop, co::WM::EXITMENULOOP, wm::ExitMenuLoop;
/// [`WM_EXITMENULOOP`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-exitmenuloop)
/// message.
}
pub_fn_wm_noparm_noret! { wm_exit_size_move, co::WM::EXITSIZEMOVE;
/// [`WM_EXITSIZEMOVE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-exitsizemove)
/// message.
}
pub_fn_wm_withparm_coret! { wm_get_dlg_code, co::WM::GETDLGCODE, wm::GetDlgCode, co::DLGC;
/// [`WM_GETDLGCODE`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-getdlgcode)
/// message.
}
/// [`WM_GETFONT`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-getfont)
/// message.
pub fn wm_get_font<F>(&self, func: F)
where F: Fn() -> AnyResult<Option<HFONT>> + 'static,
{
self.wm(co::WM::GETFONT, move |_| {
let ret_val = func()?.map_or(0, |h| h.ptr() as isize);
Ok(WmRet::HandledWithRet(ret_val))
});
}
/// [`WM_GETHMENU`](https://learn.microsoft.com/en-us/windows/win32/winmsg/mn-gethmenu)
/// message. Originally has `MN` prefix.
pub fn wm_get_hmenu<F>(&self, func: F)
where F: Fn() -> AnyResult<Option<HMENU>> + 'static
{
self.wm(co::WM::MN_GETHMENU, move |_| {
let ret_val = func()?.map_or(0, |h| h.ptr() as isize);
Ok(WmRet::HandledWithRet(ret_val))
});
}
pub_fn_wm_withparm_noret! { wm_get_min_max_info, co::WM::GETMINMAXINFO, wm::GetMinMaxInfo;
/// [`WM_GETMINMAXINFO`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-getminmaxinfo)
/// message.
}
/// [`WM_GETTEXT`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-gettext)
/// message.
pub fn wm_get_text<F>(&self, func: F)
where F: Fn(wm::GetText) -> AnyResult<u32> + 'static,
{
self.wm(co::WM::GETTEXT, move |p| {
let ret_val = func(wm::GetText::from_generic_wm(p))? as isize;
Ok(WmRet::HandledWithRet(ret_val))
});
}
/// [`WM_GETTEXTLENGTH`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-gettextlength)
/// message.
pub fn wm_get_text_length<F>(&self, func: F)
where F: Fn() -> AnyResult<u32> + 'static,
{
self.wm(co::WM::GETTEXTLENGTH, move |_| {
let ret_val = func()? as isize;
Ok(WmRet::HandledWithRet(ret_val))
});
}
pub_fn_wm_withparm_noret! { wm_get_title_bar_info_ex, co::WM::GETTITLEBARINFOEX, wm::GetTitleBarInfoEx;
/// [`WM_GETTITLEBARINFOEX`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-gettitlebarinfoex)
/// message.
}
pub_fn_wm_withparm_noret! { wm_h_scroll, co::WM::HSCROLL, wm::HScroll;
/// [`WM_HSCROLL`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-hscroll)
/// message.
}
pub_fn_wm_withparm_noret! { wm_help, co::WM::HELP, wm::Help;
/// [`WM_HELP`](https://learn.microsoft.com/en-us/windows/win32/shell/wm-help)
/// message.
}
pub_fn_wm_withparm_boolret! { wm_init_dialog, co::WM::INITDIALOG, wm::InitDialog;
/// [`WM_INITDIALOG`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-initdialog)
/// message, sent only to dialog windows. Non-dialog windows receive
/// [`WM_CREATE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-create)
/// instead.
///
/// Return `true` to set the focus to the first control in the dialog.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_init_dialog(
/// move |p: msg::wm::InitDialog| -> w::AnyResult<bool> {
/// println!("Focused HWND: {}", p.hwnd_focus);
/// Ok(true)
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_init_menu_popup, co::WM::INITMENUPOPUP, wm::InitMenuPopup;
/// [`WM_INITMENUPOPUP`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-initmenupopup)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_init_menu_popup(
/// move |p: msg::wm::InitMenuPopup| -> w::AnyResult<()> {
/// if p.hmenu.GetMenuItemID(0).unwrap() == 3001 { // check ID of 1st item
/// p.hmenu.EnableMenuItem(w::IdPos::Id(3001), false)?;
/// }
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_key_down, co::WM::KEYDOWN, wm::KeyDown;
/// [`WM_KEYDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keydown)
/// message.
}
pub_fn_wm_withparm_noret! { wm_key_up, co::WM::KEYUP, wm::KeyUp;
/// [`WM_KEYUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keyup)
/// message.
}
pub_fn_wm_withparm_noret! { wm_kill_focus, co::WM::KILLFOCUS, wm::KillFocus;
/// [`WM_KILLFOCUS`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-killfocus)
/// message.
}
pub_fn_wm_withparm_noret! { wm_l_button_dbl_clk, co::WM::LBUTTONDBLCLK, wm::LButtonDblClk;
/// [`WM_LBUTTONDBLCLK`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttondblclk)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_l_button_dbl_clk(
/// move |p: msg::wm::LButtonDblClk| -> w::AnyResult<()> {
/// println!("Point: {}x{}", p.coords.x, p.coords.y);
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_l_button_down, co::WM::LBUTTONDOWN, wm::LButtonDown;
/// [`WM_LBUTTONDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttondown)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_l_button_down(
/// move |p: msg::wm::LButtonDown| -> w::AnyResult<()> {
/// println!("Point: {}x{}", p.coords.x, p.coords.y);
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_l_button_up, co::WM::LBUTTONUP, wm::LButtonUp;
/// [`WM_LBUTTONUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttonup)
/// message.
}
pub_fn_wm_withparm_noret! { wm_m_button_dbl_clk, co::WM::MBUTTONDBLCLK, wm::MButtonDblClk;
/// [`WM_MBUTTONDBLCLK`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mbuttondblclk)
/// message.
}
pub_fn_wm_withparm_noret! { wm_m_button_down, co::WM::MBUTTONDOWN, wm::MButtonDown;
/// [`WM_MBUTTONDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mbuttondown)
/// message.
}
pub_fn_wm_withparm_noret! { wm_m_button_up, co::WM::MBUTTONUP, wm::MButtonUp;
/// [`WM_MBUTTONUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mbuttonup)
/// message.
}
pub_fn_wm_withparm_noret! { wm_menu_command, co::WM::MENUCOMMAND, wm::MenuCommand;
/// [`WM_MENUCOMMAND`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-menucommand)
/// message.
}
pub_fn_wm_withparm_coret! { wm_menu_drag, co::WM::MENUDRAG, wm::MenuDrag, co::MND;
/// [`WM_MENUDRAG`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-menudrag)
/// message.
}
pub_fn_wm_withparm_noret! { wm_menu_r_button_up, co::WM::MENURBUTTONUP, wm::MenuRButtonUp;
/// [`WM_MENURBUTTONUP`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-menurbuttonup)
/// message.
}
pub_fn_wm_withparm_noret! { wm_mouse_h_wheel, co::WM::MOUSEHWHEEL, wm::MouseHWheel;
/// [`WM_MOUSEHWHEEL`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousehwheel)
/// message.
}
pub_fn_wm_withparm_noret! { wm_mouse_hover, co::WM::MOUSEHOVER, wm::MouseHover;
/// [`WM_MOUSEHOVER`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousehover)
/// message.
}
pub_fn_wm_noparm_noret! { wm_mouse_leave, co::WM::MOUSELEAVE;
/// [`WM_MOUSELEAVE`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mouseleave)
/// message.
}
pub_fn_wm_withparm_noret! { wm_mouse_move, co::WM::MOUSEMOVE, wm::MouseMove;
/// [`WM_MOUSEMOVE`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousemove)
/// message.
}
pub_fn_wm_withparm_noret! { wm_move, co::WM::MOVE, wm::Move;
/// [`WM_MOVE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-move)
/// message.
}
pub_fn_wm_withparm_noret! { wm_mouse_wheel, co::WM::MOUSEWHEEL, wm::MouseWheel;
/// [`WM_MOUSEWHEEL`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel)
/// message.
}
pub_fn_wm_withparm_noret! { wm_moving, co::WM::MOVING, wm::Moving;
/// [`WM_MOVING`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-moving)
/// message.
}
pub_fn_wm_withparm_coret! { wm_nc_calc_size, co::WM::NCCALCSIZE, wm::NcCalcSize, co::WVR;
/// [`WM_NCCALCSIZE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-nccalcsize)
/// message.
}
pub_fn_wm_withparm_boolret! { wm_nc_create, co::WM::NCCREATE, wm::NcCreate;
/// [`WM_NCCREATE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-nccreate)
/// message.
}
pub_fn_wm_noparm_noret! { wm_nc_destroy, co::WM::NCDESTROY;
/// [`WM_NCDESTROY`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-ncdestroy)
/// message.
///
/// # Default handling
///
/// If you handle this event, you'll overwrite the default handling in:
///
/// * non-dialog [`WindowMain`](crate::gui::WindowMain);
/// * dialog [`WindowMain`](crate::gui::WindowMain).
///
/// In both cases, [`PostQuitMessage`](crate::PostQuitMessage) is called.
}
pub_fn_wm_withparm_coret! { wm_nc_hit_test, co::WM::NCHITTEST, wm::NcHitTest, co::HT;
/// [`WM_NCHITTEST`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest)
/// message.
}
pub_fn_wm_withparm_noret! { wm_nc_paint, co::WM::NCPAINT, wm::NcPaint;
/// [`WM_NCPAINT`](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint)
/// message.
}
pub_fn_wm_withparm_noret! { wm_next_dlg_ctl, co::WM::NEXTDLGCTL, wm::NextDlgCtl;
/// [`WM_NEXTDLGCTL`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/wm-nextdlgctl)
/// message.
}
pub_fn_wm_noparm_noret! { wm_null, co::WM::NULL;
/// [`WM_NULL`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-null)
/// message.
}
pub_fn_wm_noparm_noret! { wm_paint, co::WM::PAINT;
/// [`WM_PAINT`](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-paint)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// let wnd2 = wnd.clone(); // to pass into the closure
///
/// wnd.on().wm_paint(
/// move || -> w::AnyResult<()> {
/// let hdc = wnd2.hwnd().BeginPaint()?;
///
/// // hdc painting...
///
/// Ok(())
///
/// // EndPaint() automatically called
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_parent_notify, co::WM::PARENTNOTIFY, wm::ParentNotify;
/// [`WM_PARENTNOTIFY`](https://learn.microsoft.com/en-us/windows/win32/inputmsg/wm-parentnotify)
/// message.
}
pub_fn_wm_withparm_noret! { wm_power_broadcast, co::WM::POWERBROADCAST, wm::PowerBroadcast;
/// [`WM_POWERBROADCAST`](https://learn.microsoft.com/en-us/windows/win32/power/wm-powerbroadcast)
/// message.
}
pub_fn_wm_noparm_boolret! { wm_query_open, co::WM::QUERYOPEN;
/// [`WM_QUERYOPEN`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-queryopen)
/// message.
}
pub_fn_wm_withparm_noret! { wm_r_button_dbl_clk, co::WM::RBUTTONDBLCLK, wm::RButtonDblClk;
/// [`WM_RBUTTONDBLCLK`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-rbuttondblclk)
/// message.
}
pub_fn_wm_withparm_noret! { wm_r_button_down, co::WM::RBUTTONDOWN, wm::RButtonDown;
/// [`WM_RBUTTONDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-rbuttondown)
/// message.
}
pub_fn_wm_withparm_noret! { wm_r_button_up, co::WM::RBUTTONUP, wm::RButtonUp;
/// [`WM_RBUTTONUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-rbuttonup)
}
pub_fn_wm_withparm_boolret! { wm_set_cursor, co::WM::SETCURSOR, wm::SetCursor;
/// [`WM_SETCURSOR`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-setcursor)
/// message.
}
pub_fn_wm_withparm_noret! { wm_set_focus, co::WM::SETFOCUS, wm::SetFocus;
/// [`WM_SETFOCUS`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-setfocus)
/// message.
}
pub_fn_wm_withparm_noret! { wm_set_font, co::WM::SETFONT, wm::SetFont;
/// [`WM_SETFONT`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-setfont)
/// message.
}
/// [`WM_SETICON`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-seticon)
/// message.
pub fn wm_set_icon<F>(&self, func: F)
where F: Fn(wm::SetIcon) -> AnyResult<Option<HICON>> + 'static,
{
self.wm(co::WM::SETICON, move |p| {
let ret_val = func(wm::SetIcon::from_generic_wm(p))?.map_or(0, |h| h.ptr() as isize);
Ok(WmRet::HandledWithRet(ret_val))
});
}
pub_fn_wm_withparm_noret! { wm_set_redraw, co::WM::SETREDRAW, wm::SetRedraw;
/// [`WM_SETREDRAW`](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-setredraw)
/// message.
}
pub_fn_wm_withparm_boolret! { wm_set_text, co::WM::SETTEXT, wm::SetText;
/// [`WM_SETTEXT`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settext)
/// message.
}
pub_fn_wm_withparm_noret! { wm_show_window, co::WM::SHOWWINDOW, wm::ShowWindow;
/// [`WM_SHOWWINDOW`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-showwindow)
/// message.
}
pub_fn_wm_withparm_noret! { wm_size, co::WM::SIZE, wm::Size;
/// [`WM_SIZE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-size)
/// message.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, gui, msg};
///
/// let wnd: gui::WindowMain; // initialized somewhere
/// # let wnd = gui::WindowMain::new(gui::WindowMainOpts::default());
///
/// wnd.on().wm_size(
/// move |p: msg::wm::Size| -> w::AnyResult<()> {
/// println!("Client area: {}x{}",
/// p.client_area.cx,
/// p.client_area.cy,
/// );
/// Ok(())
/// },
/// );
/// ```
}
pub_fn_wm_withparm_noret! { wm_sizing, co::WM::SIZING, wm::Sizing;
/// [`WM_SIZING`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-sizing)
/// message.
}
pub_fn_wm_withparm_noret! { wm_style_changed, co::WM::STYLECHANGED, wm::StyleChanged;
/// [`WM_STYLECHANGED`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-stylechanged)
/// message.
}
pub_fn_wm_withparm_noret! { wm_style_changing, co::WM::STYLECHANGING, wm::StyleChanging;
/// [`WM_STYLECHANGING`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-stylechanging)
/// message.
}
pub_fn_wm_noparm_noret! { wm_sync_paint, co::WM::SYNCPAINT;
/// [`WM_SYNCPAINT`](https://learn.microsoft.com/en-us/windows/win32/gdi/wm-syncpaint)
/// message.
}
pub_fn_wm_withparm_noret! { wm_sys_char, co::WM::SYSCHAR, wm::SysChar;
/// [`WM_SYSCHAR`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-syschar)
/// message.
}
pub_fn_wm_withparm_noret! { wm_sys_command, co::WM::SYSCOMMAND, wm::SysCommand;
/// [`WM_SYSCOMMAND`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand)
/// message.
}
pub_fn_wm_withparm_noret! { wm_sys_dead_char, co::WM::SYSDEADCHAR, wm::SysDeadChar;
/// [`WM_SYSDEADCHAR`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-sysdeadchar)
/// message.
}
pub_fn_wm_withparm_noret! { wm_sys_key_down, co::WM::SYSKEYDOWN, wm::SysKeyDown;
/// [`WM_SYSKEYDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-syskeydown)
/// message.
}
pub_fn_wm_withparm_noret! { wm_sys_key_up, co::WM::SYSKEYUP, wm::SysKeyUp;
/// [`WM_SYSKEYUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-syskeyup)
/// message.
}
pub_fn_wm_noparm_noret! { wm_theme_changed, co::WM::THEMECHANGED;
/// [`WM_THEMECHANGED`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-themechanged)
/// message.
}
pub_fn_wm_withparm_noret! { wm_uninit_menu_popup, co::WM::UNINITMENUPOPUP, wm::UninitMenuPopup;
/// [`WM_UNINITMENUPOPUP`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-uninitmenupopup)
/// message.
}
pub_fn_wm_noparm_boolret! { wm_undo, co::WM::UNDO;
/// [`WM_UNDO`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-undo)
/// message.
}
pub_fn_wm_withparm_noret! { wm_v_scroll, co::WM::VSCROLL, wm::VScroll;
/// [`WM_VSCROLL`](https://learn.microsoft.com/en-us/windows/win32/controls/wm-vscroll)
/// message.
}
pub_fn_wm_withparm_noret! { wm_window_pos_changed, co::WM::WINDOWPOSCHANGED, wm::WindowPosChanged;
/// [`WM_WINDOWPOSCHANGED`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanged)
/// message.
}
pub_fn_wm_withparm_noret! { wm_window_pos_changing, co::WM::WINDOWPOSCHANGING, wm::WindowPosChanging;
/// [`WM_WINDOWPOSCHANGING`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanging)
/// message.
}
pub_fn_wm_withparm_noret! { wm_wts_session_change, co::WM::WTSSESSION_CHANGE, wm::WtsSessionChange;
/// [`WM_WTSSESSION_CHANGE`](https://learn.microsoft.com/en-us/windows/win32/termserv/wm-wtssession-change)
/// message.
}
pub_fn_wm_withparm_noret! { wm_x_button_dbl_clk, co::WM::XBUTTONDBLCLK, wm::XButtonDblClk;
/// [`WM_XBUTTONDBLCLK`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-xbuttondblclk)
/// message.
}
pub_fn_wm_withparm_noret! { wm_x_button_down, co::WM::XBUTTONDOWN, wm::XButtonDown;
/// [`WM_XBUTTONDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-xbuttondown)
/// message.
}
pub_fn_wm_withparm_noret! { wm_x_button_up, co::WM::XBUTTONUP, wm::XButtonUp;
/// [`WM_XBUTTONUP`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-xbuttonup)
/// message.
}
}